<template>
    <div class="app-container">
        <el-form
            :model="queryParams"
            ref="queryForm"
            size="small"
            :inline="true"
            v-show="showSearch"
            label-width="100px"
        >
            <el-form-item label="部门" prop="deptId">
                <treeselect
                    v-model="queryParams.deptId"
                    :options="deptOptions"
                    :show-count="true"
                    placeholder="请选择部门"
                    @keyup.enter.native="handleQuery"
                    style="width: 215px"
                />
            </el-form-item>

            <el-form-item label="当前员工状态" prop="staffType">
                <el-select
                    filterable
                    v-model="queryParams.staffType"
                    placeholder=""
                    clearable
                >
                    <el-option
                        v-for="item in dict.type.hrm_staff_type"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                    >
                    </el-option>
                </el-select>
            </el-form-item>

            <el-form-item label="员工姓名" prop="realName">
                <el-input
                    v-model="queryParams.realName"
                    placeholder=""
                    clearable
                    @keyup.enter.native="handleQuery"
                />
            </el-form-item>

            <el-form-item label="工号" prop="staffNum">
                <el-input
                    v-model="queryParams.staffNum"
                    placeholder=""
                    clearable
                    @keyup.enter.native="handleQuery"
                />
            </el-form-item>
            <el-form-item label="培训时间" prop="daterange">
                <el-date-picker
                    v-model="timeArr"
                    type="daterange"
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    value-format="yyyy-MM-dd"
                    @change="setChangeDate($event, 'startDate', 'endDate')"
                >
                </el-date-picker>
            </el-form-item>
            <!-- <el-form-item label="开始时间" prop="startDate">
        <el-date-picker
          clearable
          v-model="queryParams.startDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择开始时间"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间" prop="endDate">
        <el-date-picker
          clearable
          v-model="queryParams.endDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择结束时间"
        ></el-date-picker>
      </el-form-item> -->

            <!-- <el-form-item label="部门名称" prop="deptName">
        <el-input
          v-model="queryParams.deptName"
          placeholder="请输入部门名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属组织id" prop="orgId">
        <el-input
          v-model="queryParams.orgId"
          placeholder="请输入所属组织id"
          clearable
          @keyup.enter.native="handleQuery"
        /> -->
            <!-- </el-form-item> -->
            <!-- <el-form-item label="所属岗位的ID字符串" prop="postId">
        <el-input
          v-model="queryParams.postId"
          placeholder="请输入所属岗位的ID字符串"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="岗位名称" prop="postName">
        <el-input
          v-model="queryParams.postName"
          placeholder="请输入岗位名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学时" prop="classHours">
        <el-input
          v-model="queryParams.classHours"
          placeholder="请输入学时"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      
      <el-form-item label="培训地点" prop="address">
        <el-input
          v-model="queryParams.address"
          placeholder="请输入培训地点"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="举办单位" prop="organizingUnit">
        <el-input
          v-model="queryParams.organizingUnit"
          placeholder="请输入举办单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否有协议，0：无，1：有" prop="isAgreement">
        <el-input
          v-model="queryParams.isAgreement"
          placeholder="请输入是否有协议，0：无，1：有"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
            <el-form-item>
                <el-button
                    type="primary"
                    icon="el-icon-search"
                    size="mini"
                    @click="handleQuery"
                    >查询</el-button
                >
                <el-button
                    icon="el-icon-refresh"
                    size="mini"
                    @click="resetQuery"
                    >重置</el-button
                >
            </el-form-item>
        </el-form>

        <TableCard>
            <el-row :gutter="10" class="mb8">
                <el-col :span="1.5">
                    <el-button
                        type="primary"
                        plain
                        icon="el-icon-plus"
                        size="mini"
                        @click="handleAdd"
                        v-hasPermi="['hrm:training:add']"
                        >培训登记</el-button
                    >
                </el-col>
                <!-- <el-col :span="1.5">
          <el-button
            type="success"
            plain
            icon="el-icon-edit"
            size="mini"
            :disabledd="single"
            @click="handleUpdate"
            v-hasPermi="['hrm:training:edit']"
            >修改</el-button
          >
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabledd="multiple"
            @click="handleDelete"
            v-hasPermi="['hrm:training:remove']"
            >删除</el-button
          >
        </el-col> -->
                <el-col :span="1.5">
                    <el-button
                        type="warning"
                        plain
                        icon="el-icon-download"
                        size="mini"
                        @click="handleExport"
                        v-hasPermi="['hrm:training:export']"
                        >导出</el-button
                    >
                </el-col>
            </el-row>

            <el-table
                :border="Global.tableShowBorder"
                v-loading="loading"
                :data="trainingList"
                @selection-change="handleSelectionChange"
            >
                <!-- <el-table-column type="selection" width="55" align="center" /> -->
                <el-table-column
                    type="index"
                    label="序号"
                    width="55"
                    align="center"
                />
                <!-- <el-table-column label="主键" align="center" prop="id" /> -->
                <el-table-column label="姓名" align="center" prop="realName" />
                <!-- <el-table-column label="用户ID" align="center" prop="userId" /> -->
                <el-table-column label="工号" align="center" prop="staffNum" />
                <el-table-column
                    label="当前员工状态"
                    align="center"
                    prop="staffType"
                >
                    <template slot-scope="scope">
                        <dict-tag
                            :options="dict.type.hrm_staff_type"
                            :value="scope.row.staffType"
                        />
                    </template>
                </el-table-column>
                <!-- <el-table-column label="部门ID" align="center" prop="deptId" /> -->
                <el-table-column label="部门" align="center" prop="deptName" />
                <!-- <el-table-column label="所属组织id" align="center" prop="orgId" /> -->
                <!-- <el-table-column
          label="所属岗位的ID字符串"
          align="center"
          prop="postId"
        /> -->
                <el-table-column label="岗位" align="center" prop="postName" />
                <el-table-column
                    label="培训内容"
                    align="center"
                    prop="content"
                />
                <el-table-column
                    label="学时"
                    align="center"
                    prop="classHours"
                />
                <el-table-column
                    label="开始时间"
                    align="center"
                    prop="startDate"
                    width="180"
                >
                    <template slot-scope="scope">
                        <span>{{
                            parseTime(scope.row.startDate, "{y}-{m}-{d}")
                        }}</span>
                    </template>
                </el-table-column>
                <el-table-column
                    label="结束时间"
                    align="center"
                    prop="endDate"
                    width="180"
                >
                    <template slot-scope="scope">
                        <span>{{
                            parseTime(scope.row.endDate, "{y}-{m}-{d}")
                        }}</span>
                    </template>
                </el-table-column>
                <!-- <el-table-column label="培训地点" align="center" prop="address" /> -->
                <el-table-column
                    label="举办单位"
                    align="center"
                    prop="organizingUnit"
                />
                <el-table-column
                    label="是否有协议"
                    align="center"
                    prop="isAgreement"
                >
                    <template slot-scope="scope">
                        <span>{{ isAgreement(scope.row.isAgreement) }}</span>
                    </template>
                </el-table-column>
                <!-- <el-table-column
          label="证书名称"
          align="center"
          prop="certificateName"
        />
        <el-table-column label="培训理由" align="center" prop="reasons" />
        <el-table-column label="备注" align="center" prop="remark" /> -->
                <el-table-column
                    label="操作"
                    align="center"
                    class-name="small-padding fixed-width"
                    width="200"
                >
                    <template slot-scope="scope">
                        <el-button
                            size="mini"
                            type="text"
                            icon="el-icon-view"
                            @click="handleLook(scope.row)"
                            >查看</el-button
                        >
                        <el-button
                            size="mini"
                            type="text"
                            icon="el-icon-edit"
                            @click="handleUpdate(scope.row)"
                            v-hasPermi="['hrm:training:edit']"
                            >修改</el-button
                        >
                        <el-button
                            size="mini"
                            type="text"
                            icon="el-icon-delete"
                            @click="handleDelete(scope.row)"
                            v-hasPermi="['hrm:training:remove']"
                            >删除</el-button
                        >
                    </template>
                </el-table-column>
            </el-table>

            <pagination
                v-show="total > 10"
                :total="total"
                :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize"
                @pagination="getList"
            />
        </TableCard>

        <!-- 添加或修改培训计划对话框 -->
        <el-dialog
            :title="title"
            :visible.sync="open"
            width="1000px"
            append-to-body
        >
            <TableCard>
                <el-form
                    ref="form"
                    :model="form"
                    :rules="isLook ? '' : rules"
                    label-width="100px"
                >
                    <el-divider content-position="left">员工信息</el-divider>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="姓名" prop="realName">
                                <el-input
                                    :disabled="!isAdd"
                                    v-model="form.realName"
                                    placeholder="请选择姓名"
                                    readonly
                                    @focus="
                                        () => {
                                            showUserTableVision = true;
                                        }
                                    "
                                />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="工号" prop="staffNum">
                                <el-input v-model="form.staffNum" disabled />
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <!-- <el-form-item label="用户ID" prop="userId">
            <el-input v-model="form.userId" placeholder="请输入用户ID" />
          </el-form-item> -->
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="部门" prop="deptId">
                                <el-input v-model="form.deptName" disabled />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="岗位" prop="postId">
                                <el-input v-model="form.postName" disabled />
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <!-- <el-form-item label="部门名称" prop="deptName">
            <el-input v-model="form.deptName" placeholder="请输入部门名称" />
          </el-form-item> -->
                    <!-- <el-form-item label="所属组织id" prop="orgId">
            <el-input v-model="form.orgId" placeholder="请输入所属组织id" />
          </el-form-item> -->

                    <!-- <el-form-item label="岗位名称" prop="postName">
            <el-input v-model="form.postName" placeholder="请输入岗位名称" />
          </el-form-item> -->
                    <el-divider content-position="left">培训信息</el-divider>
                    <el-form-item label="培训内容" prop="content">
                        <el-input v-model="form.content" :disabled="isLook" />
                    </el-form-item>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="学时" prop="classHours">
                                <el-input
                                    v-model="form.classHours"
                                    placeholder=""
                                    :disabled="isLook"
                                />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="是否有协议" prop="isAgreement">
                                <el-select
                                    filterable
                                    v-model="form.isAgreement"
                                    placeholder=""
                                    clearable
                                    :disabled="isLook"
                                >
                                    <el-option
                                        v-for="item in $store.getters
                                            .allDefectObj['HR-WEB-125'] == 0 &&
                                        !form.id
                                            ? skillBook2
                                            : skillBook"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                    >
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="开始时间" prop="startDate">
                                <el-date-picker
                                    clearable
                                    v-model="form.startDate"
                                    type="date"
                                    value-format="yyyy-MM-dd"
                                    placeholder=""
                                    :disabled="isLook"
                                >
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="结束时间" prop="endDate">
                                <el-date-picker
                                    clearable
                                    v-model="form.endDate"
                                    type="date"
                                    value-format="yyyy-MM-dd"
                                    placeholder=""
                                    :disabled="isLook"
                                >
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="培训地点" prop="address">
                                <el-input
                                    v-model="form.address"
                                    placeholder=""
                                    :disabled="isLook"
                                />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item
                                label="举办单位"
                                prop="organizingUnit"
                            >
                                <el-input
                                    v-model="form.organizingUnit"
                                    placeholder=""
                                    :disabled="isLook"
                                />
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-form-item label="证书名称" prop="certificateName">
                        <el-input
                            v-model="form.certificateName"
                            type="textarea"
                            :rows="5"
                            placeholder=""
                            maxlength="512"
                            show-word-limit
                            :disabled="isLook"
                        />
                    </el-form-item>
                    <el-form-item label="培训理由" prop="reasons">
                        <el-input
                            v-model="form.reasons"
                            type="textarea"
                            :rows="5"
                            placeholder=""
                            maxlength="512"
                            show-word-limit
                            :disabled="isLook"
                        />
                    </el-form-item>
                    <el-form-item label="备注" prop="remark">
                        <el-input
                            v-model="form.remark"
                            type="textarea"
                            :rows="5"
                            placeholder=""
                            maxlength="512"
                            show-word-limit
                            :disabled="isLook"
                        />
                    </el-form-item>
                </el-form>
            </TableCard>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitForm" v-show="!isLook"
                    >保 存</el-button
                >
                <el-button @click="cancel">返 回</el-button>
                <el-button type="primary" @click="submitAddForm" v-show="isAdd">
                    保存并继续添加</el-button
                >
            </div>
        </el-dialog>
        <userTableDialog
            title="培训员工选择"
            :defaultParams="defaultParams"
            :open.sync="showUserTableVision"
            @confirm="setPeratorName"
        >
        </userTableDialog>
    </div>
</template>

<script>
import {
    listTraining,
    getTraining,
    delTraining,
    addTraining,
    updateTraining,
} from "@/api/hrm/trainning.js";
import { treeselect } from "@/api/system/dept";
import { listPostAll } from "@/api/system/post";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
export default {
    name: "Training",
    dicts: ["hrm_staff_type"],
    components: { Treeselect },
    data() {
        var contentMaxLength = (rule, value, callback) => {
            if (value && value.length > 64) {
                callback(new Error("长度不能超过 64 个字符"));
            } else {
                callback();
            }
        };
        var classHoursMaxLength = (rule, value, callback) => {
            if (value && value.length > 8) {
                callback(new Error("长度不能超过 8 个字符"));
            } else {
                callback();
            }
        };
        var skillDate = (rule, value, callback) => {
            if (
                value != null &&
                this.form.startDate != null &&
                this.compareDates(this.form.startDate, value) == 1
            ) {
                callback(new Error("结束日期不应在开始日期之前"));
            } else {
                callback();
            }
        };
        return {
            timeArr: [],
            isAdd: false,
            isLook: false,
            skillBook: [
                { value: 1, label: "有" },
                { value: 0, label: "无" },
            ],
            skillBook2: [
                { value: 1, label: "1" },
                { value: 0, label: "0" },
            ],
            defaultParams: {
                isLink: true,
                //在职用户，
                staffTypes: "1,4,5,6",
            },
            showUserTableVision: false,
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示查询条件
            showSearch: true,
            // 总条数
            total: 0,
            // 培训计划表格数据
            trainingList: [],
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                // orderByColumn: "createTime",
                // isAsc: "descending",
                realName: null,
                userId: null,
                staffNum: null,
                deptId: null,
                deptName: null,
                orgId: null,
                postId: null,
                postName: null,
                content: null,
                classHours: null,
                startDate: null,
                endDate: null,
                address: null,
                organizingUnit: null,
                isAgreement: null,
                certificateName: null,
                reasons: null,
            },
            // 表单参数
            form: {},
            deptOptionsArray: [],
            postList: [],
            deptOptions: [],
            // 表单校验
            rules: {
                realName: [
                    {
                        required: true,
                        message: "姓名不能为空",
                        trigger: "change",
                    },
                ],
                content: [
                    {
                        required: true,
                        message: "培训内容不能为空",
                        trigger: "blur",
                    },
                    {
                        validator: contentMaxLength,
                        message: "长度不能超过 64 个字符",
                        trigger: "blur",
                    },
                ],
                classHours: [
                    {
                        required: true,
                        message: "学时不能为空",
                        trigger: "blur",
                    },
                    {
                        validator: classHoursMaxLength,
                        message: "长度不能超过 8 个字符",
                        trigger: "blur",
                    },
                ],
                startDate: [
                    {
                        required: true,
                        message: "开始时间不能为空",
                        trigger: "blur",
                    },
                ],
                endDate: [
                    {
                        required: true,
                        message: "结束时间不能为空",
                        trigger: "blur",
                    },
                    {
                        validator: skillDate,
                        message: "结束日期不应在开始日期之前",
                        trigger: "blur",
                    },
                ],
                address: [
                    {
                        required: true,
                        message: "培训地点不能为空",
                        trigger: "blur",
                    },
                    {
                        validator: contentMaxLength,
                        message: "长度不能超过 64 个字符",
                        trigger: "blur",
                    },
                ],
                organizingUnit: [
                    {
                        required: true,
                        message: "举办单位不能为空",
                        trigger: "blur",
                    },
                    {
                        validator: contentMaxLength,
                        message: "长度不能超过 64 个字符",
                        trigger: "blur",
                    },
                ],
                isAgreement: [
                    {
                        required: true,
                        message: "是否有协议不能为空",
                        trigger: "blur",
                    },
                ],
            },
        };
    },
    created() {
        this.getList();
        this.getTreeselect();
        this.getPostList();
    },
    methods: {
        setChangeDate(item, startDate, endDate) {
            console.log(item, "时间段");
            if (item.length > 0) {
                this.queryParams.startDate = item[0];
                this.queryParams.endDate = item[1];
            } else {
                this.queryParams.startDate = null;
                this.queryParams.endDate = null;
            }
        },
        isAgreement(value) {
            for (let item of this.skillBook) {
                if (item.value === value) {
                    return item.label;
                }
            }
        },
        submitAddForm() {
            // bug HR-WEB-126
            if (this.$store.getters.allDefectObj["HR-WEB-126"] == 0) {
                this.submitForm();
                return;
            }

            this.$refs["form"].validate((valid) => {
                if (valid) {
                    let staffNum = this.form.staffNum;
                    let realName = this.form.realName;
                    let postId = this.form.postId;
                    let deptId = this.form.deptId;
                    let postName = this.form.postName;
                    let deptName = this.form.deptName;
                    // if (!this.form.certificateName) {
                    //     this.form.certificateName = "无";
                    // }
                    addTraining(this.form).then((response) => {
                        this.$modal.msgSuccess("新增成功");
                        this.open = false;
                        this.getList();
                        this.reset();

                        // bug HR-WEB-126
                        if (
                            this.$store.getters.allDefectObj["HR-WEB-127"] == 1
                        ) {
                            this.form.staffNum = staffNum;
                            this.form.realName = realName;
                            this.form.postId = postId;
                            this.form.deptId = deptId;
                            this.form.postName = postName;
                            this.form.deptName = deptName;
                        }

                        this.open = true;
                        this.title = "继续添加培训进修信息";
                    });
                }
            });
        },
        compareDates(dateString1, dateString2) {
            // 尝试将字符串解析为Date对象
            const date1 = new Date(dateString1);
            const date2 = new Date(dateString2);

            // 检查是否解析成功（即不是Invalid Date）
            if (isNaN(date1.getTime()) || isNaN(date2.getTime())) {
                console.error("Invalid date string");
                return null;
            }
            // 比较日期
            if (date1 < date2) {
                return -1; // dateString1 在 dateString2 之前
            } else if (date1 > date2) {
                return 1; // dateString1 在 dateString2 之后
            } else {
                return 0; // 两个日期相同
            }
        },
        parseSelectTree(id) {
            let tempObj = this.deptOptionsArray.find((item) => item.id == id);
            if (tempObj) {
                this.form.deptName = tempObj.label;
            }
        },
        flattenArray(arr) {
            let result = [];
            for (let i = 0; i < arr.length; i++) {
                let item = arr[i];
                result.push(item);
                if (item.children) {
                    result = result.concat(this.flattenArray(item.children));
                }
            }
            return result;
        },

        parsePostName(ids) {
            if (!ids) {
                return "";
            }
            if (ids != null && ids != "") {
                let nameArr = [];
                let selIds = ids.split(",");
                this.postList.forEach((item) => {
                    selIds.forEach((sel) => {
                        if (item.postId == sel) {
                            nameArr.push(item.postName);
                        }
                    });
                });
                this.form.postName = nameArr.join(",");
            }
        },
        getPostList() {
            listPostAll().then((res) => {
                this.postList = res.data;
            });
        },
        /** 查询部门下拉树结构 */
        getTreeselect() {
            treeselect().then((response) => {
                this.deptOptions = response.data;
                this.deptOptionsArray = this.flattenArray(this.deptOptions);
            });
        },
        setPeratorName(row) {
            this.form.realName = row.realName;

            //bug 124
            if (this.$store.getters.allDefectObj["HR-WEB-124"] == 0) {
            } else {
                this.form.staffNum = row.staffNum;
                this.form.postId = row.postId;
                this.form.deptId = row.deptId;
                this.parseSelectTree(this.form.deptId);
                this.parsePostName(this.form.postId);
            }
        },
        /** 查询培训计划列表 */
        getList() {
            this.loading = true;
            listTraining(this.queryParams).then((response) => {
                this.trainingList = response.rows;
                this.total = response.total;
                this.loading = false;
            });
        },
        // 取消按钮
        cancel() {
            this.open = false;
            this.reset();
        },
        // 表单重置
        reset() {
            this.form = {};
            this.resetForm("form");
        },
        /** 查询按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.queryParams.startDate = null;
            this.queryParams.endDate = null;
            this.timeArr = [];
            this.handleQuery();
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map((item) => item.id);
            this.single = selection.length !== 1;
            this.multiple = !selection.length;
        },
        /** 新增按钮操作 */
        handleAdd() {
            this.isAdd = true;
            this.isLook = false;
            this.reset();
            this.open = true;
            this.title = "培训登记";
        },
        /** 查看按钮操作 */
        handleLook(row) {
            this.isAdd = false;
            this.isLook = true;
            this.reset();
            const id = row.id || this.ids;
            getTraining(id).then((response) => {
                this.form = response.data;
                this.open = true;
                if (
                    this.$store.getters.allDefectObj["HR-WEB-128"] == 1 &&
                    !this.form.certificateName
                ) {
                    this.form.certificateName = "无";
                }
                this.title = "培训信息查看";
            });
        },
        /** 修改按钮操作 */
        handleUpdate(row) {
            this.isAdd = false;
            this.isLook = false;
            this.reset();
            const id = row.id || this.ids;
            getTraining(id).then((response) => {
                this.form = response.data;
                this.open = true;
                this.title = "培训信息修改";
            });
        },
        /** 提交按钮 */
        submitForm() {
            this.$refs["form"].validate((valid) => {
                if (valid) {
                    // if (!this.form.certificateName) {
                    //     this.form.certificateName = "无";
                    // }
                    if (this.form.id != null) {
                        updateTraining(this.form).then((response) => {
                            this.$modal.msgSuccess("修改成功");
                            this.open = false;
                            this.getList();
                        });
                    } else {
                        addTraining(this.form).then((response) => {
                            this.$modal.msgSuccess("新增成功");
                            this.open = false;
                            this.getList();
                        });
                    }
                }
            });
        },
        /** 删除按钮操作 */
        handleDelete(row) {
            const ids = row.id || this.ids;
            this.$modal
                .confirm("确定要删除该培训信息吗")
                .then(function () {
                    return delTraining(ids);
                })
                .then(() => {
                    this.getList();
                    this.$modal.msgSuccess("删除成功");
                })
                .catch(() => {});
        },
        /** 导出按钮操作 */
        // handleExport() {
        //     this.download(
        //         "hrm/training/export",
        //         {
        //             ...this.queryParams,
        //         },
        //         `training_${new Date().getTime()}.xlsx`
        //     );
        // },

        /** 导出按钮操作 */
        handleExport() {
            const date = new Date();
            const year = date.getFullYear();
            const month = String(date.getMonth() + 1).padStart(2, "0");
            const day = String(date.getDate()).padStart(2, "0");
            this.download(
                "hrm/training/export",
                {
                    ...this.queryParams,
                },
                `员工培训信息_${year}年${month}月${day}日.xlsx`
            );
        },
    },
};
</script>
